package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetMealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "套餐相关接口")
@RestController
@Slf4j
@RequestMapping("/admin/setmeal")
public class SetMealController {

    @Autowired
    SetMealService setMealService;

    @PutMapping
    @ApiOperation("修改套餐")
    public Result changeSetMeal(@RequestBody SetmealDTO setmealDTO)
    {
        return setMealService.changeSetMeal(setmealDTO);
    }


    @GetMapping("/{id}")
    @ApiOperation("根据id查询套餐")
    public Result<SetmealVO> getById(@PathVariable Long id){
        return setMealService.getById(id);
    }

    @PostMapping
    @ApiOperation("新增套餐")
    public Result save(@RequestBody SetmealDTO setmealDTO)
    {
        return setMealService.save(setmealDTO);
    }


    @GetMapping("/page")
    @ApiOperation("分页查询")
    public Result<PageResult> page(SetmealPageQueryDTO setmealPageQueryDTO){
        return setMealService.page(setmealPageQueryDTO);
    }

    @PostMapping("/status/{status}")
    @ApiOperation("修改套餐起售状态")
    public Result status(@PathVariable Integer status,Long id){
        log.info("接收到修改套餐状态参数 status：{}，id：{}",status,id);
        return setMealService.status(status,id);
    }


    @ApiOperation("批量删除套餐")
    @DeleteMapping
    public Result delete(@RequestParam List<Long> ids)
    {
        log.info("批量删除套餐：ids，{}",ids);
        return setMealService.deleteByIds(ids);
    }
}
